interface IPoint {
    // x: number
    // y: number
    drawPoint: () => void
    getDistances: (p: IPoint) => number

    X: number
    // getX: () => number
    getY: () => number
    // setX: (value) => void
    setY: (value:number) => void
}

export class PointImpl implements IPoint {
    // x: number
    // y: number

    // constructor(x?: number, y: number=3) {
    //     this.x = x
    //     this.y = y
    // }

    // constructor(public x: number, public y: number = 3) { }

    constructor(private _x: number, private _y: number = 3) { }

    drawPoint = () => {
        console.log('x:', this._x, ' y:', this._y);

    }
    getDistances = (p: IPoint) => {
        return Math.pow(p.X - this._x, 2) + Math.pow(p.getY() - this._y, 2)
    }

    // setX = (value: number) => {
    //     if (value < 0) {
    //         throw new Error('value不能小于0')
    //     }
    //     this.x = value
    // }

    // getX = () => {
    //     return this.x
    // }

    setY = (value: number) => {
        if (value < 0) {
            throw new Error('value不能小于0')
        }
        this._y = value
    }

    getY = () => {
        return this._y
    }

    set X(value: number) {
        if (value < 0) {
            throw new Error('value不能小于0')
        }
        this._x = value
    }

    get X() {
        return this._x
    }
}
